<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <a href="javascript:;" onclick="setCookie('data','qweasd\'');">设置Cookie</a>
    <a href="javascript:;" onclick="console.log(getCookie('data'));">获取Cookie</a>
    <a href="javascript:;" onclick="delCookie('data');">删除Cookie</a>
</body>
<script>
    //JS操作cookies方法!
    //写cookies
    function setCookie(name, value) {
        var Days = 30;
        var exp = new Date();
        exp.setTime(exp.getTime() +10000);
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
        console.log(document.cookie)
    }
    //读cookies
    function getCookie(name) {
        var arr;
        var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg)) {
            console.log(arr);
            console.log(reg);
            return unescape(arr[2]);
        } else
            return null;
    }
    //删除cookise
    function delCookie(name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = getCookie(name);
        if (cval != null)
            document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
</script>

</html>